// 采购管理

import r from '@/utils/request'
import { type ListParams, type ListResponseType, type ResponseType } from '../types'

enum API {
    purchaseList = "/purchase/list", // 采购申请列表
    purchaseFoodsList = "/purchaseFoods/list", //根据采购id获取采购物品列表
    purchaseGet = '/purchase/get',// 根据id获取单条采购申请信息
    purchaseAdd = '/purchase/add', //提交采购申请
    purchaseCheck = '/purchase/check', // 收获验收
    purchaseDelete = '/purchase/delete',
}

export interface purchaseItem {
    id: number;
}

export function purchaseDeleteAPI(id: number): Promise<ResponseType<string>> {
    return r.delete(API.purchaseDelete + '/' + id)
}

export interface getPurchaseListParams extends ListParams{
    companyId?:string
    state?:string
    beginDate?:string
    endDate?:string
}
export interface getPurchaseListResAPI {
    id:             number;
    companyId:      number;
    receiveTime:    string;
    addTime:        string;
    addAccountId:   number;
    picture:        string;
    remarks:        string;
    state:          string;
    addAccountName: string;
    companyName:    string;
    counts:         number;
    purchasePrice:  number;
    foods:          string;
}

export function getPurchaseListAPI(Params:getPurchaseListParams):Promise<ListResponseType<getPurchaseListResAPI[]>> {
    return r.get(API.purchaseList,Params)
}


export interface getPurchaseFoodsListResAPI {
    id:             number;
    purchaseId:     number;
    foodName:       string;
    unit:           string;
    supplierId:     number;
    wholePrice:     number;
    sellPrice:      number;
    purchasePrice:  number;
    purchaseCounts: number;
    receiveCounts:  number;
    supplierName:   string;
}


export function getPurchaseFoodsListAPI(id:number):Promise<ResponseType<{list:getPurchaseFoodsListResAPI[]}>> {
    return r.get(API.purchaseFoodsList+'/'+id)
}

export interface getPurchaseGetResAPI {
    id:             number;
    companyId:      number;
    receiveTime:    string;
    addTime:        string;
    addAccountId:   number;
    picture:        string;
    remarks:        string;
    state:          string;
    addAccountName: string;
    companyName:    string;
    counts:         number;
    purchasePrice:  string;
    foods:          string;
}


export function PurchaseGetAPI(id:number):Promise<ListResponseType<getPurchaseGetResAPI[]>> {
    return r.get(API.purchaseGet+'/'+id)
}
export interface  purchaseAddParamsFood {
    foodName:       string;
    unit:           string;
    supplierId:     number;
    wholePrice:     number;
    sellPrice:      number;
    purchasePrice:  number;
    purchaseCounts: number;
    totalCost?:  any;
}

export interface purchaseAddParams {
    receiveTime: string;
    remarks:     string;
    foods:       purchaseAddParamsFood[];
}

export interface purchaseAddResFoodAPI {
    id:             number;
    purchaseId:     number;
    foodName:       string;
    unit:           string;
    supplierId:     number;
    wholePrice:     number;
    sellPrice:      number;
    purchasePrice:  number;
    purchaseCounts: number;
    receiveCounts:  number;
    supplierName:   string;
}

export interface purchaseAddResAPI {
    id:             number;
    companyId:      number;
    receiveTime:    string;
    addTime:        string;
    addAccountId:   number;
    picture:        string;
    remarks:        string;
    state:          string;
    addAccountName: string;
    companyName:    string;
    counts:         number;
    purchasePrice:  string;
    foods:          purchaseAddResFoodAPI[];
}

export function purchaseAdd(Params:purchaseAddParams):Promise<ResponseType<purchaseAddResAPI[]>> {
    return r.post(API.purchaseAdd,Params)
}

export interface purchaseCheckFoodParams {
    id:            number;
    receiveCounts: number;
}

export interface purchaseCheckParams {
    id:      number;
    picture: string;
    foods:   purchaseCheckFoodParams[];
}

export interface purchaseCheckResFoodAPI {
    id:             number;
    purchaseId:     number;
    foodName:       string;
    unit:           string;
    supplierId:     number;
    wholePrice:     string;
    sellPrice:      string;
    purchasePrice:  string;
    purchaseCounts: number;
    receiveCounts:  number;
    supplierName:   string;
}

export interface purchaseCheckResAPI {
    id:             number;
    companyId:      number;
    receiveTime:    string;
    addTime:        string;
    addAccountId:   number;
    picture:        string;
    remarks:        string;
    state:          string;
    addAccountName: string;
    companyName:    string;
    counts:         number;
    purchasePrice:  string;
    foods:          purchaseCheckResFoodAPI[];
}

export function purchaseCheck(Params:purchaseCheckParams):Promise<ResponseType<purchaseCheckResAPI>> {
    return r.put(API.purchaseCheck,Params)
}